package final2107.day13;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo02 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        System.out.println("请输入类名：");
        Scanner scanner = new Scanner(System.in);
        String className = scanner.nextLine();

        //根据类名加载类对象
        Class cls = Class.forName(className);
        //创建对象
        Object target = cls.newInstance();
        //获取类中的所有方法筛选以test开头的，并让其执行
        Method[] methods = cls.getDeclaredMethods();
        for (Method method:methods){
            if (method.getName().startsWith("test")){
                Object returnVal = method.invoke(target);
                System.out.println("返回值："+returnVal);
            }
        }

    }
}
